//
//  Question.m
//  MTDBFROMJSON
//
//  Created by kingPC on 13-8-31.
//  Copyright (c) 2013年 kingPC. All rights reserved.
//

#import "Question.h"
#import "DatabaseOperation.h"

@implementation Question

-(id)initWithDirectory:(NSDictionary*)d{
    self=[super init];
    if (self) {
        [self setName:[d objectForKey:@"NAME"]];
        [self setQid:[d objectForKey:@"id"]];
        [self setAnswerid:[d objectForKey:@"ANSWERID"]];
        DatabaseOperation *db=[[[DatabaseOperation alloc]initWithDbName:database_name]autorelease];
        NSString *sql=[NSString stringWithFormat:@"select * from `t_answers` where Qid=%@",self.Qid];
        NSArray *resource=[db querryTable:sql];
        for (int i=1;i<=[resource count];i++) {
            NSString *key=[NSString stringWithFormat:@"answer%d",i];
            Answer *a=[[[Answer alloc]initWithDirectory:[resource objectAtIndex:i-1]]autorelease];
            [self setValue:a forKey:key];
        }
    }
    return self;
}

@end
